from flask import session
from functools import wraps
from tools.response import ResponseInvalidSession

def pack_session(f):
    @wraps(f)
    def decorated_function(*args, **kwargs):
        session_uid = session.get('uid')
        username = session.get('username')

        if not session_uid or not username:
            return ResponseInvalidSession()

        data = {
            'session': {
                'username': username,
                'uid': session_uid
            },
            'readable': True,
            'writeable': False,
            'checkable': False,
            'route': kwargs if kwargs else {}
        }
        return f(data)
    return decorated_function

